﻿using UnityEngine;
using System.Collections;

public class BossAppear : MonoBehaviour {
	[SerializeField] float Transparnt = 0f;
	[SerializeField] float TSpeed = 0.5f;
	[SerializeField] float penqi = 1f;
	[SerializeField] float PSpeed = 0.5f;
	[SerializeField] Material m_Mat;

	//public bool startDisapper = false;
	//public bool penqiED = false;

	void Start () {
		m_Mat = GetComponent<Renderer>().material;
	}

	/*void Update () {
		if (startDisapper) {
			StartCoroutine (BossAppearing ());
			startDisapper = false;
		}
		if (penqiED) {
			StartCoroutine (BossPenqi ());
			penqiED = false;
		}
	}*/
	/// <summary>
	/// 让boss出现、消失或染上喷漆
	/// </summary>
	/// <param name="FuncName">三选一：Appear, Disappear, Penqi</param>
	public void StartIE(string FuncName){
		if (FuncName == "Appear") {
			StartCoroutine (BossAppearing ());
		} else if (FuncName == "Disappear") {
			StartCoroutine (BossDisappearing ());
		} else if (FuncName == "Penqi") {
			StartCoroutine (BossPenqi ());
		} else {
			Debug.LogWarning ("FuncName Error");
		}
	}

	IEnumerator BossAppearing(){
		while (true) {
			Transparnt = Mathf.Clamp(Transparnt-Time.deltaTime*TSpeed, 0f, 1f);
			m_Mat.SetFloat("_Alpha", Transparnt);
			if (Transparnt <= 0f) {
				break;
			}
			yield return null;
		}
		yield return null;
	}
	IEnumerator BossDisappearing(){
		while (true) {
			Transparnt = Mathf.Clamp(Transparnt+Time.deltaTime*TSpeed, 0f, 1f);
			m_Mat.SetFloat("_Alpha", Transparnt);
			if (Transparnt >= 1f) {
				break;
			}
			yield return null;
		}
		yield return null;
	}
	IEnumerator BossPenqi(){
		while (true) {
			penqi = Mathf.Clamp(penqi-Time.deltaTime*PSpeed, 0f, 1f);
			m_Mat.SetFloat("_PenqiRate", penqi);
			if (penqi <= 0f) {
				break;
			}
			yield return null;
		}
		yield return null;
	}
	/// <summary>
	/// 让染上喷漆的boss恢复原样
	/// </summary>
	public void cleanBoss(){
		m_Mat.SetFloat("_Alpha", 0f);
		m_Mat.SetFloat("_PenqiRate", 1f);
	}
}
